<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: class.checkbox.php 398 2014-01-18 16:01:01Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 398 $
* 	zuletzt geaendert von:	$Author: $
* 	Datum:					$Date: 2014-01-18 16:01:01 +0000 (Sat, 18 Jan 2014) $
*
* 	extends by dirk.mueller (edv-mueller.com)
* 	http://www.itdotmedia.de
*
* --------------------------------------------------------------------------------------
* 	based on:
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
* 	Copyright (c) since 2011 SEO:mercari
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
include_once (DIR_WS_INCLUDES.'modules/product_konfigurator/class.base.php');

class checkbox extends base {

  function get_price($product_id, $price, $post) {
    global $db;
    $price_value = 0;
    if (!isset($post[$this->group['id']]) || $post[$this->group['id']] == '' ) return $price;
    
    if (!is_array($post[$this->group['id']]))
      $post[$this->group['id']] = array($post[$this->group['id']]);

    $sql = "
      select
        product_id, price
      from
        ".TABLE_KONFIGURATOR_PRODUCT_OPTION." po
      where
        po.product_id = '".$product_id."'
        and konfigurator_option_group = '".$this->group['id']."'
        and konfigurator_option in ('".implode("', '", $post[$this->group['id']])."')";
    $query = $db->db_query($sql, true);
    $price_value = 0;
		if($query->_numOfRows > 0){
      while(!$query->EOF) {
        $price_value += ($query->fields['price'] == null ? 0 : $query->fields['price']);
        $query->moveNext();
      }
    }

    $this->_calculate_price($price, $price_value);
    return $price;
  }

  function get_description($product_id, $post) {
    global $db;
    $description = array('option_name' => '', 'option_value' => array());

    if (!isset($post[$this->group['id']]) || $post[$this->group['id']] == '' ) {
			$description['option_value'] = '';
    	return $description;
    }

    if (!is_array($post[$this->group['id']]))
      $post[$this->group['id']] = array($post[$this->group['id']]);

    $sql = "
      select
      	po.product_id,
      	og.konfigurator_optiongroups_name, o.konfigurator_options_name
      from
      	".TABLE_KONFIGURATOR_PRODUCT_OPTION." po
      	inner join ".TABLE_KONFIGURATOR_OPTIONGROUPS." og
      		on og.konfigurator_optiongroups_id = po.konfigurator_option_group
      	inner join ".TABLE_KONFIGURATOR_OPTIONS." o
      		on o.konfigurator_optiongroups_id = po.konfigurator_option_group
      		and o.konfigurator_options_id = po.konfigurator_option
      where
        po.product_id = '".$product_id."'
        and konfigurator_option_group = '".$this->group['id']."'
        and konfigurator_option in ('".implode("', '", $post[$this->group['id']])."')";

    $query = $db->db_query($sql, true);
		if($query->_numOfRows > 0) {
      while(!$query->EOF) {
        $description['option_name'] = $query->fields['konfigurator_optiongroups_name'];
        $description['option_value'][] = $query->fields['konfigurator_options_name'];
        $query->moveNext();
      }
    }

    $description['option_value'] = implode(', ', $description['option_value']);
    return  $description;
  }


}